package com.bootdo.wx.api;

import com.bootdo.common.utils.R;
import com.bootdo.common.utils.StringUtils;
import com.bootdo.wx.service.MemberFollowService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * Created by HP on 2019/6/11.
 */
@Controller
@RequestMapping("/api/memberFollow")
public class ApiMemberFollowController {

    @Autowired
    private MemberFollowService memberFollowService;


    /*关注/取消关注 商品*/
    @ResponseBody
    @RequestMapping("/setFollow")
    public R setFollow(@RequestBody Map<String, Object> params) {
        if (!params.containsKey("userId") || StringUtils.isBlank(params.get("userId").toString())
                || !params.containsKey("goodsId") || StringUtils.isBlank(params.get("goodsId").toString())
                ) {
            return R.error("缺少参数");
        }
        try {
            return memberFollowService.setFollow(params);
        } catch (Exception e) {
            return R.error("获取小类列表失败");
        }
    }


    /*查看关注商品列表*/
    @ResponseBody
    @RequestMapping("/getFollowList")
    public R getFollowList(@RequestBody Map<String, Object> params) {
        if (!params.containsKey("userId") || StringUtils.isBlank(params.get("userId").toString())
                ) {
            return R.error("缺少参数");
        }
        try {
            PageInfo<Map<String,Object>> list = memberFollowService.getFollowList(params);
            return R.ok().put("data",list);
        } catch (Exception e) {
            return R.error("获取小类列表失败");
        }
    }

    /*我的足迹  用关注这个表*/
    @ResponseBody
    @RequestMapping("/getHistoryList")
    public R getHistoryList(@RequestBody Map<String, Object> params) {
        if (!params.containsKey("userId") || StringUtils.isBlank(params.get("userId").toString())
                ||!params.containsKey("date")
        ) {
            return R.error("缺少参数");
        }
        try {
            return memberFollowService.getHistoryList(params);

        } catch (Exception e) {
            return R.error("获取小类列表失败");
        }
    }














}
